import App from '../App'


const login = r => require.ensure([], () => r(require('../login')), '../login');
const memberCentre = r => require.ensure([], () => r(require('../page/member/memberCentre')), 'memberCentre');


import member from './member'
import corporation from './corporation'
import healthManagement from './healthManagement'
import finance from './finance'
import service from './service'
import serviceCenter from './serviceCenter'
import subsidyOperating from './subsidyOperating'
import elderlyMC from './elderlyMC'

export default [{
  path: '',
  redirect: to => {
    let token = to.hash.split("#access_token=")[1];
    let refresh_token = to.hash.split("&refresh_token=")[1];
    if(token) {
      window.sessionStorage.setItem("access_token", token.split("&")[0]);
      window.sessionStorage.setItem("refresh_token", refresh_token);
      let query = to.query;
      let name = query.name;
      if(name) {
        delete query.name;
        return {name: name, query: query};
      }
    }
    return {name:"memberCentre"};
    // return {name:"memberFile"};
  }
}, {
  path: '/app',
  component: App,  //顶层路由，对应index.html
  children: [      //二级路由。对应App.vue
    {path: '', redirect: 'member/memberCentre'},   //地址为空时跳转订单管理页面
    // {path: '', redirect: 'member/memberFile'},   //地址为空时跳转档案页面
    ...member,
    ...corporation,
    ...healthManagement,
    ...service,
    ...serviceCenter,
    ...finance,
    ...subsidyOperating,
    ...elderlyMC
  ]
},{
  path: '/login',
  component: login, //顶级路由，对应login.html
  name:'login'
}]
